//
// Created by Administrator on 2017/4/16.
//

#ifndef SELETIONSORT_SORTTESTHELPER_H
#define SELETIONSORT_SORTTESTHELPER_H

#include <iostream>
#include <ctime>
#include <cassert>

using namespace std;

namespace SortTestHelper{

    /**
     * 生成有n个元素的随机数组，每个元素的随机范围为[rangeL ,rangeR]
     * @param n  生成随机数组元素的个数
     * @param rangeL 开始的位置
     * @param rangeR  结束的位置
     * @return 生成数组的头指针
     */
    int* generateRandomArray(int n , int rangeL ,int rangeR){

        assert( rangeL <= rangeR);
        int *arr = new int[n];
        srand(time(NULL));
        for( int i = 0 ; i < n ;i ++)
            arr[i] = rand() % (rangeR - rangeL + 1) + rangeL ;
        return arr;
    }

    template <typename T>
    void printArray(T arr[],int n){

        for (int i = 0; i < n; ++i) {
            cout<<arr[i]<<" ";
        }
        cout << endl;
    }

    template <typename T>
    bool isSort(T arr[],int n){

        for (int i = 0; i < n-1; ++i)

            if (arr[i] > arr[i + 1])
                return false;
        return true;

    }
    template <typename T>
    void testSort(string sortName , void(*sort)(T[], int) ,T arr[] , int n){

        clock_t startTime = clock();
        sort(arr , n);
        clock_t endTime = clock();

        assert(isSort(arr,n));
        cout << sortName << ":" << double(endTime - startTime)/CLOCKS_PER_SEC << "s" << endl;

        return;
    }




}
#endif //SELETIONSORT_SORTTESTHELPER_H
